package com.lai.berry_core.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.ContentFrameLayout;

import com.lai.berry_core.R;
import com.lai.berry_core.delegate.BerryDelegate;

import me.yokeyword.fragmentation.SupportActivity;

/**
 * Created on 2017/10/27.
 * @author laifolai
 *         <p>
 *         描述：
 *         主要功能：
 */

public abstract class ProxyActivity extends SupportActivity {
    /**
     * 设置根 页面（fragment）
     * @return
     */
    public abstract BerryDelegate setRootDelegate();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initContainer(savedInstanceState);
    }
    private void initContainer(@Nullable Bundle savedInstanceState){
        final ContentFrameLayout container=new ContentFrameLayout(this);
        container.setId(R.id.delegate_container);
        setContentView(container);
        if (savedInstanceState==null){//第一次加载
            loadRootFragment(R.id.delegate_container,setRootDelegate());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.gc();
        System.runFinalization();
    }
}
